<!-- 后结算模块-财务管理-验票管理-->
<template>
  <div class="nissin-list-box">
    <el-container class="template-box">
      <!-- tab切换 -->
      <tabs
        is-new-tabs
        :active-index="tabIndex"
        :tabs-arr="indexTabsArr"
        @returnIndex="tabsHandle"
      />
      <!-- 搜索 -->
      <el-header height="auto">
        <SearchForm
          label-width="110px"
          :data="indexSearchData"
          :compact-data="indexSearchData.slice(0,2)"
          show-collapse
          @searchForm="searchForm"
          @resetForm="resetForm"
          :submit-loading='submitLoading'
        />
      </el-header>
      <!-- 列表 -->
      <el-editable
        v-loading="submitLoading"
        :data="dataList"
        height="400"
        :columns="columsData">
        <!-- 发票影像 -->
        <template
          slot="default-invoiceUrl"
          slot-scope="scope">
          <div style="display:flex; justify-content: center;">
            <el-image
              v-if="scope.row.invoiceUrl"
              @click="toLookDetails(scope.row)"
              style="width: 23px; height: 16.6px;"
              :src="imageicon"/>
          </div>
        </template>
        <template
          slot="default-action"
          slot-scope="scope">
          <el-button
            size="small"
            v-if="scope.row.orderStatus ===1"
            @click.stop="ticketcheck(scope.row)"
            type="text text-primary"
          >审核</el-button>
          <el-button
            size="small"
            @click.stop="toOrderDetail(scope.row)"
            type="text text-primary">详情</el-button>
        </template>
      </el-editable>
      <!-- 分页模块 -->
      <el-pagination
        class="pagination"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="curPage"
        :page-sizes="PAGE_NUMBER"
        :page-size="pageSize"
        :layout="PAGINATION_LAYOUT"
        :total="totalElements"
      />
      <invoice-details
        :display-or-not="displayOrNotDetails"
        :invoice-url="activeInvoiceUrl"
        :invoice-no="activeInvoiceNo"
        @cancelDialog="cancelDialog" />
    </el-container>
  </div>
</template>

<script>
import {
  hospitalSettleVerifyManagerList,
  hospitalSettleVerifyManagerStatisticsCount
} from '@const/beforeSettleApi'
import { indexTabsArr, columsData, indexSearchData } from './const'
import tabs from '@components/tabs/index.vue'
import SearchForm from '@components/businesscomponents/search'
import ElEditable from '@components/el-editable'
import InvoiceDetails from '@/moduleComponents/beforeSettle/invoiceDetails'
import { PAGE_NUMBER, PAGINATION_LAYOUT } from '@const/common'
import { hasIn, cloneDeep } from 'lodash'
import { formatDate } from '@const/filter'
export default {
  components: { tabs, ElEditable, SearchForm, InvoiceDetails },
  data () {
    return {
      imageicon: require('@assets/icon/beforeSettle/imageicon.png'),
      // 查看发票详情
      displayOrNotDetails: false,
      activeInvoiceUrl: '',
      activeInvoiceNo: '',
      tabIndex: 3, // tab默认值
      // tab字段
      indexTabsArr: cloneDeep(indexTabsArr),
      // 搜索标题字段
      indexSearchData,
      // 搜索返回内容
      searchData: {},
      submitLoading: false,
      columsData, // 列表表头
      dataList: [], // 列表数据
      curPage: 1, // 当前页
      PAGE_NUMBER, // 页码数组
      PAGINATION_LAYOUT, // 页码功能布局
      pageSize: PAGE_NUMBER[0], // 一页的数量
      totalElements: 0, // 总共的条数
      tabIndexVal: 0
    }
  },
  mounted () {
    this.getList()
    this.getCount()
  },
  methods: {
    // 查看发票详情
    toLookDetails (val) {
      this.activeInvoiceUrl = val.invoiceUrl
      this.activeInvoiceNo = val.invoiceNo
      this.displayOrNotDetails = true
    },
    cancelDialog () {
      this.activeInvoiceUrl = ''
      this.activeInvoiceNo = ''
      this.displayOrNotDetails = false
      this.this.getList()
    },
    // 搜索功能-点击查询
    searchForm (condition) {
      this.searchData = condition
      this.getList()
    },

    // 点击重置
    resetForm (condition) {
      this.curPage = 1
      this.searchData = condition
      this.getList()
    },
    // 获取列表
    async getList () {
      this.submitLoading = true
      const res = await this.$axios({
        method: 'post',
        url: hospitalSettleVerifyManagerList,
        data: {
          ...this.searchData,
          orderStatus: this.tabIndexVal,
          page: this.curPage,
          pageSize: this.pageSize,
          type: 1
        }
      })
      this.dataList = hasIn(res, ['data', 'payload'])
        ? res.data.payload.content || []
        : []
      this.allAmount = res.data.payload.allAmount
      this.totalElements = res.data.payload.totalElements
      this.submitLoading = false
    },
    // 根据状态获取对应数量
    async getCount () {
      const res = await this.$axios({
        method: 'post',
        url: hospitalSettleVerifyManagerStatisticsCount
      })
      let arr = hasIn(res, 'data.payload') ? res.data.payload : []
      const cloneIndexTabs = cloneDeep(indexTabsArr)
      let allCount = null // 全部的数量
      arr.forEach(item => {
        allCount += item.count
      })

      // 获取对应tab值
      cloneIndexTabs.forEach(item => {
        arr.forEach(ite => {
          if (ite.statusCode === item.val) {
            item.badge = { value: ite.count || null }
          }
        })
      })
      cloneIndexTabs[3].badge.value = allCount || null
      this.indexTabsArr = cloneIndexTabs
    },
    // tabs切换处理事件
    tabsHandle (index) {
      this.tabIndexVal =
        this.indexTabsArr[index].val === 'null'
          ? null
          : this.indexTabsArr[index].val
      this.curPage = 1
      this.getList()
    },
    // 验票
    ticketcheck (val) {
      this.$router.push({
        path: `${this.$route.path}/ticketcheck`,
        query: {
          type: 'ticketcheck',
          invoiceNo: val.invoiceNo,
          id: val.orderId
        }
      })
    },
    // 详情
    // 需要传应付单状态来判断该票是否是通过或者拒绝
    toOrderDetail (val) {
      this.$router.push({
        path: `${this.$route.path}/ticketcheck`,
        query: {
          id: val.orderId,
          invoiceNo: val.invoiceNo,
          orderStatus: val.orderStatus
        }
      })
    },
    // 页码更改
    handleSizeChange (size) {
      this.pageSize = size
      this.getList()
    },

    // 切换不一样的页面,重置一切数据
    handleCurrentChange (curPage) {
      this.curPage = curPage
      this.getList()
    }
  }
}
</script>
<style lang="less" scoped>
@import '../m-front-common/pc/assets/var.less';
.nissin-list-box {
  background: @bgColor;
  .el-header {
    background: #fff;
    padding: 8px;
    margin-bottom: 8px;
  }
  /deep/.template-box {
    height: 100%;
    overflow: auto;
    .searchform {
      display: flex;
      flex-wrap: wrap;

      .el-form-item {
        margin-right: 20px;
      }
      .el-input {
        width: 200px;
      }
    }
    .purchasemoney {
      border: 1px solid #dfe2e8;
      padding: 0 2px;
      .el-input__inner {
        border: none;
      }
    }
    .pagination {
      padding-top: 10px;
      display: flex;
      justify-content: flex-end;
      padding-right: 0;
    }
  }
}
</style>
